package com.lijy.employee.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lijy.employee.dao.DepartmentDao;
import com.lijy.employee.domain.Department;
import com.lijy.employee.domain.PageBean;
@Service
public class DepartmentServiceImpl implements DepartmentService {

	@Autowired
	private DepartmentDao departmentDao;

	@Override
	public List<Department> findAll() {
		return departmentDao.findAll();
	}

	@Override
	@Transactional
	public PageBean<Department> findByPage(int currPage) {
		PageBean<Department> pageBean = new PageBean<Department>();
		pageBean.setCurrPage(currPage);
		int pageSize = 5;
		pageBean.setPageSize(pageSize);
		int totalCount = departmentDao.findCount();
		pageBean.setTotalCount(totalCount);
		double tc = totalCount;
		Double num = Math.ceil(tc/pageSize);
		pageBean.setTotalPage(num.intValue());
		int begin = (currPage - 1) * pageSize;
		List<Department> list = departmentDao.findByPage(begin, pageSize);
		pageBean.setList(list);
		return pageBean;
	}

	@Override
	public void delete(String did) {
		departmentDao.delete(did);
	}

	@Override
	public Department findById(String did) {
		return departmentDao.findById(did);
	}

	@Override
	public void save(Department department) {
	    departmentDao.save(department);	
	}

	@Override
	public void update(Department department) {
		departmentDao.update(department);
	}

}
